page.tsx 863 B

12345678910111213141516171819202122232425262728
  1. import { fetchJson } from '@/lib/utils/server';
  2. import { ResultDto } from '@/types/response/common';
  3. import { ChannelDetail } from '@/types/channel';
  4. import { notFound, permanentRedirect } from 'next/navigation';
  5. import { buildWatchUrl } from '@/lib/utils/channel';
  6. import WatchView from './WatchView';
  7. type Props = {
  8. params: Promise<{ identifier: string }>;
  9. };
  10. export default async function WatchPage({ params }: Props) {
  11. const { identifier } = await params;
  12. const decoded = decodeURIComponent(identifier);
  13. const res: ResultDto<ChannelDetail> = await fetchJson(`/api/channel/${encodeURIComponent(decoded)}`, { method: 'GET' });
  14. if (!res.data) {
  15. notFound();
  16. }
  17. const canonical = buildWatchUrl(res.data);
  18. const current = `/watch/${decoded}`;
  19. if (current !== canonical) {
  20. permanentRedirect(canonical);
  21. }
  22. return <WatchView channel={res.data} />;
  23. }